package com.zye.servlet;

import com.zye.JDBCUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/update")
public class updateStudent extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf-8");
        String name = req.getParameter("name");
        int age = Integer.parseInt(req.getParameter("age"));
        String gender = req.getParameter("gender");
        String address = req.getParameter("address");
        String idcard = req.getParameter("idcard");
        int id = Integer.parseInt(req.getParameter("id"));
        int rows = JDBCUtils.update("update student set name=?,age=?,gender=?,address=?,idcard=? where id =?",name,age,gender,address,idcard,id);
        if(rows>0){
            System.out.println("修改成功");
            resp.getWriter().write("修改成功， 姓名为："+name +"  年龄是"+age+"  性别是"+gender+"  地址是"+address+"  身份证号是"+idcard);
        }
    }
}
